package com.zz.arrays;

public class Student implements Comparable<Student>{
    private String name;
    private double height;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, double height, int age) {
        this.name = name;
        this.height = height;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        /**
         * 这里是this和o比较
         * 约定1：如果this 大于 o 则返回正整数
         * 约定2,：如果this 小于 o 则返回负整数
         * 约定2,：如果this 等于 o 则返回0
         */
        //方法1：按照年龄排序
//        if(this.age > o.age){
//            return 1;
//        }else if(this.age < o.age){
//            return -1;
//        }
//        return 0;
        //方法2
        return this.age - o.age;
    }

    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", height=" + height + ", age=" + age + '}';
    }
}
